
package com.bear.cmcc.NetTestHTTP.component;

import com.bear.cmcc.NetTestHTTP.util.JsonUtil;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

public class ProvinceBean extends BaseBean {

    /**
     * 省份名称
     */
    private String province_name;

    /**
     * 在线TD的手机数量。
     */
    private int onLine_TD_size = 0;

    /**
     * 在线2G的手机数量。
     */
    private int onLine_2G_size = 0;

    /**
     * 在线WLAN的手机数量。
     */
    private int onLine_WLAN_size = 0;

    private JSONArray citys_2g = null;

    private JSONArray citys_td = null;

    public JSONArray getCitys_2g() {
        return citys_2g;
    }

    public void setCitys_2g(JSONArray citys_2g) {
        this.citys_2g = citys_2g;
    }

    public JSONArray getCitys_td() {
        return citys_td;
    }

    public void setCitys_td(JSONArray citys_td) {
        this.citys_td = citys_td;
    }

    public String getProvince_name() {
        return province_name;
    }

    public void setProvince_name(String province_name) {
        this.province_name = province_name;
    }

    public int getOnLine_TD_size() {
        return onLine_TD_size;
    }

    public void setOnLine_TD_size(int onLine_TD_size) {
        this.onLine_TD_size = onLine_TD_size;
    }

    public int getOnLine_2G_size() {
        return onLine_2G_size;
    }

    public void setOnLine_2G_size(int onLine_2G_size) {
        this.onLine_2G_size = onLine_2G_size;
    }

    public int getOnLine_WLAN_size() {
        return onLine_WLAN_size;
    }

    public void setOnLine_WLAN_size(int onLine_WLAN_size) {
        this.onLine_WLAN_size = onLine_WLAN_size;
    }

    /**
     * 获取2G网络情况的城市信息。
     * 
     * @return ArrayList<CityBean> 移动不会为null
     */
    public ArrayList<CityBean> get2GCitys() {
        ArrayList<CityBean> result = new ArrayList<CityBean>();
        if (citys_2g != null) {
            try {
                JSONObject jsonObj = null;
                CityBean cityBean = null;
                for (int j = 0; j < citys_2g.length(); j++) {
                    jsonObj = ((JSONObject) citys_2g.opt(j));
                    if (jsonObj != null) {
                        try {
                            cityBean = new CityBean();
                            cityBean.setCity_name(jsonObj.getString(JsonUtil.JSON_name));
                            cityBean.setDownSpeed((int)jsonObj
                                    .getDouble(JsonUtil.JSON_AverageSpeed));
//                            cityBean.setTwoG_Rand(jsonObj.getInt(JsonUtil.JSON_Rank));
                          //TODO scj服务器中文件还没有该数据，所以下面先屏蔽
//                            cityBean.setDroppingRate(jsonObj.getInt(JsonUtil.JSON_droppingRate));
//                            cityBean.setElectricalLevel(jsonObj
//                                    .getInt(JsonUtil.JSON_electricalLevel));
//                            cityBean.setSignalStrength(jsonObj.getInt(JsonUtil.JSON_signalStrength));
                            result.add(cityBean);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }

    /**
     * 获取TD网络情况的城市信息。
     * 
     * @return ArrayList<CityBean> 移动不会为null
     */
    public ArrayList<CityBean> getTDCitys() {
        ArrayList<CityBean> result = new ArrayList<CityBean>();
        if (citys_td != null) {
            try {
                JSONObject jsonObj = null;
                CityBean cityBean = null;
                for (int j = 0; j < citys_td.length(); j++) {
                    jsonObj = ((JSONObject) citys_td.opt(j));
                    if (jsonObj != null) {
                        try {
                            cityBean = new CityBean();
                            cityBean.setCity_name(jsonObj.getString(JsonUtil.JSON_name));
                            cityBean.setDownSpeed((int)jsonObj.getDouble(JsonUtil.JSON_AverageSpeed));
//                            cityBean.setTd_Rand(jsonObj.getInt(JsonUtil.JSON_Rank));
                            //TODO scj服务器中文件还没有该数据，所以下面先屏蔽
//                            cityBean.setDroppingRate(jsonObj.getInt(JsonUtil.JSON_droppingRate));
//                            cityBean.setElectricalLevel(jsonObj
//                                    .getInt(JsonUtil.JSON_electricalLevel));
//                            cityBean.setSignalStrength(jsonObj.getInt(JsonUtil.JSON_signalStrength));
                            result.add(cityBean);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return result;
    }

    @Override
    public String toString() {
        return "ProvinceBean [ province_name=" + province_name + ", onLine_TD_size="
                + onLine_TD_size + ", onLine_2G_size=" + onLine_2G_size + ", onLine_WLAN_size="
                + onLine_WLAN_size + ", toString()=" + super.toString() + "]";
    }

}
